class Solution {
public:
    int maxProfit(vector<int>& prices)
    {
        int sum = 0;
        int Min = 0x3f3f3f3f;
        for (int i = 0; i < prices.size(); i++)
        {
            sum = max(sum, prices[i] - Min);
            Min = min(Min, prices[i]);
        }
        return sum;
    }
};